#include <stdio.h>

#define BCD_TO_DEC(val) (((val)&15) + ((val)>>4)*10)

unsigned char hex_bcd(unsigned char a)
{
	unsigned char th, tl;

	th = a / 10;
	tl = a - th * 10;

	a = (th << 4) + tl;
	
	return a;
}

int to_bcd(int a)
{
	int ret = 0, sh = 0;

	while ( a > 0 ) {
		ret |= ( a % 10 ) << sh;
		a /= 10;
		sh += 4;
	}

	return ret;
}
